<?php

namespace App\Containers\AppSection\Project\Tasks;

use App\Containers\AppSection\Project\Data\Repositories\ConditionRepository;
use App\Containers\AppSection\Project\Models\Condition;
use App\Ship\Exceptions\UpdateResourceFailedException;
use App\Ship\Parents\Tasks\Task;

class UpdateConditionTask extends Task
{
    protected ConditionRepository $repository;

    public function __construct(ConditionRepository $repository)
    {
        $this->repository = $repository;
    }

    public function run(int $id, array $data): Condition
    {
        try {
            return $this->repository->update($data, $id);
        } catch (Exception $exception) {
            throw new UpdateResourceFailedException();
        }
    }
}
